package com.hongtu.supplychain.finance.application;

import com.hongtu.supplychain.finance.log.RequestBodyLogger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.context.embedded.MultipartConfigFactory;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import javax.servlet.MultipartConfigElement;
import java.util.ArrayList;
import java.util.List;

/**
 * 用于配置和启动引导
 */
@EnableFeignClients(basePackages={"com.hongtu.supplychain.finance"})
@EnableDiscoveryClient
@SpringBootApplication
@ComponentScan(basePackages={"com.hongtu.supplychain.finance"})
public class ConsumerApplication {

	@Bean
	FilterRegistrationBean requestBodyLoggerFilter() {
		FilterRegistrationBean registrationBean = new FilterRegistrationBean();
		registrationBean.setFilter(new RequestBodyLogger());
		List<String> urlPatterns = new ArrayList();
		urlPatterns.add("/hongtu/*");
		registrationBean.setUrlPatterns(urlPatterns);
		return registrationBean;
	}

	@Bean
	public MultipartConfigElement multipartConfigElement() {
		MultipartConfigFactory factory = new MultipartConfigFactory();
		factory.setMaxFileSize("128KB"); //KB,MB
		factory.setMaxRequestSize("256KB");
		return factory.createMultipartConfig();
	}
	public static void main(String[] args) {
		SpringApplication.run(ConsumerApplication.class, args);
	}

}
